
#include "CUtility.h"

char *localeToUTF8(char *src)
{
	static char *buf = NULL;
	if(buf){
		free(buf);
		buf = NULL;
	}
	wchar_t *unicode_buf;
	int nRetLen = MultiByteToWideChar(CP_ACP,0,src,-1,NULL,0);
	unicode_buf = (wchar_t*)malloc((nRetLen+1)*sizeof(wchar_t));
	MultiByteToWideChar(CP_ACP,0,src,-1,unicode_buf,nRetLen);
	nRetLen = WideCharToMultiByte(CP_UTF8,0,unicode_buf,-1,NULL,0,NULL,NULL);
	buf = (char*)malloc(nRetLen+1);
	WideCharToMultiByte(CP_UTF8,0,unicode_buf,-1,buf,nRetLen,NULL,NULL);
	free(unicode_buf);
	return buf;
}